home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 123 / cdrom123.iso / essenc / extens / wweb / Web Developer.xpi / chrome / webdeveloper.jar / content / webdeveloper / sidebar / edit_css.js next >
Encoding:
Text File  |  2004-11-21  |  21.4 KB  |  601 lines

  1. var webdeveloper_editCSSSelectedTab = -1;
  2. var webdeveloper_timeoutID          = null;
  3. var webdeveloper_updateFrequency    = 500;
  4.  
  5. // Applies the CSS
  6. function webdeveloper_applyCSS()
  7. {
  8.     const content         = window.top.document.getElementById("content");
  9.     const mainTabBox      = content.mTabBox;
  10.     const contentDocument = content.browsers[mainTabBox.selectedIndex].contentDocument;
  11.     const styleElement    = contentDocument.getElementById("webdeveloper-edit-css-style");
  12.     const textBoxes       = document.getElementById("webdeveloper-edit-css-tab-panels").getElementsByTagName("textbox");
  13.  
  14.     var styleText = "";
  15.  
  16.     // Loop through the text boxes
  17.     for(var i = 0; i < textBoxes.length; i++)
  18.     {
  19.         styleText += textBoxes[i].value;
  20.     }
  21.  
  22.     // If the style element exists and the style text is not the same
  23.     if(styleElement && styleText != styleElement.innerHTML)
  24.     {
  25.         webdeveloper_removeAllChildNodes(styleElement);
  26.         styleElement.appendChild(contentDocument.createTextNode(styleText));
  27.     }
  28. }
  29.  
  30. // Clear the CSS
  31. function webdeveloper_clearCSS()
  32. {
  33.     webdeveloper_getSelectedPanel().firstChild.value = "";
  34. }
  35.  
  36. // Reinitializes the sidebar when the page changes
  37. function webdeveloper_contentPageLoad(event)
  38. {
  39.     const preferencesService = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService).getBranch("");
  40.  
  41.     // If the page is the target and the URI matches
  42.     if(event.originalTarget && event.target && event.target.contentDocument && event.target.getAttribute && event.target.getAttribute("id") == "content" && event.originalTarget.documentURI == event.target.contentDocument.documentURI)
  43.     {
  44.         // If the CSS stick preference is set to true
  45.         if(preferencesService.prefHasUserValue("webdeveloper.edit.css.stick") && preferencesService.getBoolPref("webdeveloper.edit.css.stick"))
  46.         {
  47.             webdeveloper_initializeEditCSS(false);
  48.         }
  49.         else
  50.         {
  51.             webdeveloper_resetCSS();
  52.         }
  53.     }
  54. }
  55.  
  56. // Handles a browser tab being selected
  57. function webdeveloper_editCSSMainTabSelect(event)
  58. {
  59.     const selectedTab = window.top.document.getElementById("content").mTabBox.selectedIndex;
  60.  
  61.     // If the selected tab is different
  62.     if(selectedTab != webdeveloper_editCSSSelectedTab)
  63.     {
  64.         const preferencesService = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService).getBranch("");
  65.  
  66.         webdeveloper_editCSSSelectedTab = selectedTab;
  67.  
  68.         // If the CSS stick preference is set to true
  69.         if(preferencesService.prefHasUserValue("webdeveloper.edit.css.stick") && preferencesService.getBoolPref("webdeveloper.edit.css.stick"))
  70.         {
  71.             webdeveloper_initializeEditCSS(false);
  72.         }
  73.         else
  74.         {
  75.             webdeveloper_resetCSS();
  76.         }
  77.     }
  78. }
  79.  
  80. // Handles a tab being selected
  81. function webdeveloper_editCSSTabSelect(event)
  82. {
  83.     const selectedTab = document.getElementById("webdeveloper-edit-css-tab-box").selectedTab;
  84.     const nextTab     = selectedTab.nextSibling;
  85.     const previousTab = selectedTab.previousSibling;
  86.  
  87.     // If there is a previous tab
  88.     if(previousTab)
  89.     {
  90.         // Remove the after selected attribute
  91.         if(previousTab.hasAttribute("afterselected"))
  92.         {
  93.             previousTab.removeAttribute("afterselected");
  94.         }
  95.  
  96.         // Remove the before selected attribute
  97.         if(previousTab.hasAttribute("beforeselected"))
  98.         {
  99.             previousTab.removeAttribute("beforeselected");
  100.         }
  101.     }
  102.  
  103.     // If there is a next tab
  104.     if(nextTab)
  105.     {
  106.         // Remove the after selected attribute
  107.         if(nextTab.hasAttribute("afterselected"))
  108.         {
  109.             nextTab.removeAttribute("afterselected");
  110.         }
  111.  
  112.         // Remove the before selected attribute
  113.         if(nextTab.hasAttribute("beforeselected"))
  114.         {
  115.             nextTab.removeAttribute("beforeselected");
  116.         }
  117.     }
  118. }
  119.  
  120. // Unloads edit CSS
  121. function webdeveloper_editCSSUnload()
  122. {
  123.     const content         = window.top.document.getElementById("content");
  124.     const mainTabBox      = content.mTabBox;
  125.     const currentDocument = content.browsers[mainTabBox.selectedIndex].contentDocument;
  126.     const styleElement    = currentDocument.getElementById("webdeveloper-edit-css-style");
  127.     const styleSheetList  = currentDocument.styleSheets;
  128.     const tabBox          = document.getElementById("webdeveloper-edit-css-tab-box");
  129.  
  130.     var styleSheet = null;
  131.  
  132.     window.clearTimeout(webdeveloper_timeoutID);
  133.     window.top.removeEventListener("load", webdeveloper_contentPageLoad, true);
  134.     mainTabBox.removeEventListener("select", webdeveloper_editCSSMainTabSelect, true);
  135.     tabBox.removeEventListener("select", webdeveloper_editCSSTabSelect, true);
  136.  
  137.     // If the style element exists
  138.     if(styleElement)
  139.     {
  140.         styleElement.parentNode.removeChild(styleElement);
  141.     }
  142.  
  143.     // Loop through the style sheets
  144.     for(var i = 0; i < styleSheetList.length; i++)
  145.     {
  146.         styleSheet = styleSheetList[i];
  147.  
  148.         webdeveloper_enableStyleSheet(styleSheet);
  149.     }
  150. }
  151.  
  152. // Enables a style sheet
  153. function webdeveloper_enableStyleSheet(styleSheet)
  154. {
  155.     const ownerNode = styleSheet.ownerNode;
  156.  
  157.     var cssRule = null;
  158.  
  159.     // Loop through the the style sheet rules
  160.     for(var i = 0; i < styleSheet.cssRules.length; i++)
  161.     {
  162.         cssRule = styleSheet.cssRules[i];
  163.  
  164.         // If this is an import rule
  165.         if(cssRule.type == 3)
  166.         {
  167.             webdeveloper_enableStyleSheet(cssRule.styleSheet);
  168.         }
  169.     }
  170.  
  171.     // If the style sheet does not have an owner node or is not an alternate style sheet
  172.     if(!ownerNode || ownerNode.nodeType == 7 || !ownerNode.hasAttribute("rel") || ownerNode.getAttribute("rel") != "alternate stylesheet")
  173.     {
  174.         styleSheet.disabled = false;
  175.     }
  176. }
  177.  
  178. // Returns the selected panel
  179. function webdeveloper_getSelectedPanel()
  180. {
  181.     var selectedPanel = document.getElementById("webdeveloper-edit-css-tab-panels").selectedPanel;
  182.  
  183.     // If the selected panel is not set
  184.     if(!selectedPanel)
  185.     {
  186.         selectedPanel = document.getElementById("webdeveloper-edit-css-tab-panels").firstChild;
  187.     }
  188.  
  189.     return selectedPanel;
  190. }
  191.  
  192. // Initializes the edit CSS sidebar
  193. function webdeveloper_initializeEditCSS(reset)
  194. {
  195.     const content            = window.top.document.getElementById("content");
  196.     const mainTabBox         = content.mTabBox;
  197.     const currentDocument    = content.browsers[mainTabBox.selectedIndex].contentDocument;
  198.     const headElementList    = currentDocument.getElementsByTagName("head");
  199.     const preferencesService = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService).getBranch("");
  200.     const tabBox             = document.getElementById("webdeveloper-edit-css-tab-box");
  201.     const textBoxes          = document.getElementById("webdeveloper-edit-css-tab-panels").getElementsByTagName("textbox");
  202.  
  203.     var styleElement = currentDocument.getElementById("webdeveloper-edit-css-style");
  204.     var styleText    = "";
  205.  
  206.     // Try to remove the event listeners
  207.     try
  208.     {
  209.         window.top.removeEventListener("load", webdeveloper_contentPageLoad, true);
  210.         mainTabBox.removeEventListener("select", webdeveloper_editCSSMainTabSelect, true);
  211.         tabBox.removeEventListener("select", webdeveloper_editCSSTabSelect, true);
  212.     }
  213.     catch(exception)
  214.     {
  215.         // Do nothing
  216.     }
  217.  
  218.     window.top.addEventListener("load", webdeveloper_contentPageLoad, true);
  219.     mainTabBox.addEventListener("select", webdeveloper_editCSSMainTabSelect, true);
  220.     tabBox.addEventListener("select", webdeveloper_editCSSTabSelect, true);
  221.  
  222.     // If resetting
  223.     if(reset)
  224.     {
  225.         webdeveloper_updateStickCSS();
  226.         webdeveloper_retrieveCSS();
  227.     }
  228.  
  229.     // If the style element does not exist
  230.     if(!styleElement)
  231.     {
  232.         styleElement = currentDocument.createElement("style");
  233.  
  234.         styleElement.setAttribute("id", "webdeveloper-edit-css-style");
  235.         styleElement.setAttribute("type", "text/css");
  236.  
  237.         // If there is a head element
  238.         if(headElementList.length > 0)
  239.         {
  240.             headElementList[0].appendChild(styleElement);
  241.         }
  242.         else
  243.         {
  244.             currentDocument.documentElement.appendChild(styleElement);
  245.         }
  246.     }
  247.  
  248.     // If the edit CSS update frequency preference is set
  249.     if(preferencesService.prefHasUserValue("webdeveloper.edit.css.update.frequency"))
  250.     {
  251.         webdeveloper_updateFrequency = preferencesService.getIntPref("webdeveloper.edit.css.update.frequency");
  252.     }
  253.  
  254.     webdeveloper_refreshStyles();
  255. }
  256.  
  257. // Loads new CSS
  258. function webdeveloper_loadCSS()
  259. {
  260.     const filePicker   = Components.classes["@mozilla.org/filepicker;1"].createInstance(Components.interfaces.nsIFilePicker);
  261.     const stringBundle = document.getElementById("webdeveloper-string-bundle");
  262.  
  263.     filePicker.appendFilter(stringBundle.getString("webdeveloper_styleSheetDescription"), "*.css");
  264.     filePicker.init(window, stringBundle.getString("webdeveloper_editCSSLoadStyleSheetTitle"), filePicker.modeOpen);
  265.  
  266.     // If the user selected a style sheet
  267.     if(filePicker.show() == filePicker.returnOK)
  268.     {
  269.         const inputStream      = Components.classes["@mozilla.org/network/file-input-stream;1"].createInstance(Components.interfaces.nsIFileInputStream);
  270.         const scriptableStream = Components.classes["@mozilla.org/scriptableinputstream;1"].createInstance(Components.interfaces.nsIScriptableInputStream);
  271.  
  272.         inputStream.init(filePicker.file, 0x01, 0444, null);
  273.         scriptableStream.init(inputStream);
  274.  
  275.         webdeveloper_getSelectedPanel().firstChild.value = scriptableStream.read(scriptableStream.available());
  276.  
  277.         scriptableStream.close();
  278.         inputStream.close();
  279.     }
  280. }
  281.  
  282. // Refreshes the styles on the page
  283. function webdeveloper_refreshStyles()
  284. {
  285.     webdeveloper_applyCSS();
  286.  
  287.     // If the update frequency is greater than zero
  288.     if(webdeveloper_updateFrequency > 0)
  289.     {
  290.         webdeveloper_timeoutID = window.setTimeout(webdeveloper_refreshStyles, webdeveloper_updateFrequency);
  291.     }
  292. }
  293.  
  294. // Resets the edited CSS
  295. function webdeveloper_resetCSS()
  296. {
  297.     const content           = window.top.document.getElementById("content");
  298.     const mainTabBox        = content.mTabBox;
  299.     const styleElement      = content.browsers[mainTabBox.selectedIndex].contentDocument.getElementById("webdeveloper-edit-css-style");
  300.     const tabPanels         = document.getElementById("webdeveloper-edit-css-tab-panels");
  301.     const tabs              = document.getElementById("webdeveloper-edit-css-tabs");
  302.     const tabsChildren      = tabs.childNodes;
  303.  
  304.     // If the style element exists
  305.     if(styleElement)
  306.     {
  307.         styleElement.parentNode.removeChild(styleElement);
  308.     }
  309.  
  310.     webdeveloper_removeAllChildNodes(tabPanels);
  311.  
  312.     // Loop through the tabs
  313.     for(var i = 0; i < tabsChildren.length; i++)
  314.     {
  315.         tabs.removeChild(tabsChildren[i]);
  316.     }
  317.  
  318.     webdeveloper_initializeEditCSS(true);
  319. }
  320.  
  321. // Retrieves the CSS from the current page
  322. function webdeveloper_retrieveCSS()
  323. {
  324.     const content            = window.top.document.getElementById("content");
  325.     const mainTabBox         = content.mTabBox;
  326.     const currentDocument    = content.browsers[mainTabBox.selectedIndex].contentDocument;
  327.     const preferencesService = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService).getBranch("");
  328.     const stringBundle       = document.getElementById("webdeveloper-string-bundle");
  329.     const tabs               = document.getElementById("webdeveloper-edit-css-tabs");
  330.     const tabPanels          = document.getElementById("webdeveloper-edit-css-tab-panels");
  331.  
  332.     var cssRule          = null;
  333.     var inlineStylesText = "";
  334.     var mediaList        = null;
  335.     var ownerNode        = null;
  336.     var result           = null;
  337.     var results          = new Array();
  338.     var styleSheet       = null;
  339.     var styleSheetList   = currentDocument.getElementsByTagName("style");
  340.     var tab              = null;
  341.     var tabPanel         = null;
  342.     var textBox          = null;
  343.     var textBoxStyle     = "";
  344.  
  345.     // If the edit CSS background color preference is set
  346.     if(preferencesService.prefHasUserValue("webdeveloper.edit.css.color.background"))
  347.     {
  348.         textBoxStyle += "background-color: " + preferencesService.getCharPref("webdeveloper.edit.css.color.background") + " !important;";
  349.     }
  350.  
  351.     // If the edit CSS text color preference is set
  352.     if(preferencesService.prefHasUserValue("webdeveloper.edit.css.color.text"))
  353.     {
  354.         textBoxStyle += "color: " + preferencesService.getCharPref("webdeveloper.edit.css.color.text") + " !important;";
  355.     }
  356.  
  357.     // If the edit CSS font preference is set
  358.     if(preferencesService.prefHasUserValue("webdeveloper.edit.css.font"))
  359.     {
  360.         textBoxStyle += "font-size: " + preferencesService.getIntPref("webdeveloper.edit.css.font") + "px !important;";
  361.     }
  362.  
  363.     // Loop through the inline style sheets
  364.     for(var i = 0; i < styleSheetList.length; i++)
  365.     {
  366.         inlineStylesText += styleSheetList[i].innerHTML.trim() + "\n\n";
  367.     }
  368.  
  369.     styleSheetList = currentDocument.styleSheets;
  370.  
  371.     // Loop through the style sheets
  372.     for(i = 0; i < styleSheetList.length; i++)
  373.     {
  374.         styleSheet = styleSheetList[i];
  375.         mediaList  = styleSheet.media.mediaText;
  376.         ownerNode  = styleSheet.ownerNode;
  377.  
  378.         // If this is an inline style sheet
  379.         if(styleSheet.href == currentDocument.documentURI)
  380.         {
  381.             // Loop through the the style sheet rules
  382.             for(var j = 0; j < styleSheet.cssRules.length; j++)
  383.             {
  384.                 cssRule = styleSheet.cssRules[j];
  385.  
  386.                 // If this is an import rule
  387.                 if(cssRule.type == 3)
  388.                 {
  389.                     webdeveloper_retrieveStyleSheetDetails(cssRule.styleSheet, textBoxStyle, results);
  390.                 }
  391.             }
  392.         }
  393.         else if((!mediaList || mediaList.indexOf("screen") != -1 || mediaList.indexOf("all") != -1) && (!ownerNode || ownerNode.nodeType == 7 || !ownerNode.hasAttribute("rel") || ownerNode.getAttribute("rel") != "alternate stylesheet"))
  394.         {
  395.             webdeveloper_retrieveStyleSheetDetails(styleSheet, textBoxStyle, results);
  396.         }
  397.     }
  398.  
  399.     // If there are inline styles
  400.     if(inlineStylesText != "")
  401.     {
  402.         tab      = document.createElement("tab");
  403.         tabPanel = document.createElement("tabpanel");
  404.         textBox  = document.createElement("textbox");
  405.  
  406.         tab.setAttribute("label", stringBundle.getString("webdeveloper_editCSSInlineStyles"));
  407.         textBox.setAttribute("flex", "1");
  408.         textBox.setAttribute("multiline", "true");
  409.         textBox.setAttribute("style", textBoxStyle);
  410.         textBox.setAttribute("value", inlineStylesText);
  411.  
  412.         // If the edit CSS wrap preference is not set to true
  413.         if(!preferencesService.prefHasUserValue("webdeveloper.edit.css.wrap") || !preferencesService.getBoolPref("webdeveloper.edit.css.wrap"))
  414.         {
  415.             textBox.setAttribute("wrap", "off");
  416.         }
  417.  
  418.         tabPanel.appendChild(textBox);
  419.  
  420.         results.push(new Array(tab, tabPanel));
  421.     }
  422.  
  423.     // Loop through the results
  424.     for(i = 0; i < results.length; i++)
  425.     {
  426.         result = results[i];
  427.  
  428.         tabs.appendChild(result[0]);
  429.         tabPanels.appendChild(result[1]);
  430.     }
  431.  
  432.     // If there are no tabs
  433.     if(tabs.childNodes.length == 0)
  434.     {
  435.         tab      = document.createElement("tab");
  436.         tabPanel = document.createElement("tabpanel");
  437.         textBox  = document.createElement("textbox");
  438.  
  439.         tab.setAttribute("label", stringBundle.getString("webdeveloper_editCSS"));
  440.         textBox.setAttribute("flex", "1");
  441.         textBox.setAttribute("multiline", "true");
  442.         textBox.setAttribute("style", textBoxStyle);
  443.  
  444.         // If the edit CSS wrap preference is not set to true
  445.         if(!preferencesService.prefHasUserValue("webdeveloper.edit.css.wrap") || !preferencesService.getBoolPref("webdeveloper.edit.css.wrap"))
  446.         {
  447.             textBox.setAttribute("wrap", "off");
  448.         }
  449.  
  450.         tabs.appendChild(tab);
  451.         tabPanel.appendChild(textBox);
  452.         tabPanels.appendChild(tabPanel);
  453.     }
  454.  
  455.     tabs.selectedIndex = 0;
  456. }
  457.  
  458. // Retrieves the style sheet details
  459. function webdeveloper_retrieveStyleSheetDetails(styleSheet, textBoxStyle, results)
  460. {
  461.     const preferencesService = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService).getBranch("");
  462.     const request            = new XMLHttpRequest();
  463.     const styleSheetHref     = styleSheet.href;
  464.     const position           = styleSheetHref.lastIndexOf("/");
  465.  
  466.     var cssRule    = null;
  467.     var path       = styleSheetHref;
  468.     var stylesText = "";
  469.     var tab        = document.createElement("tab");
  470.     var tabPanel   = document.createElement("tabpanel");
  471.     var textBox    = document.createElement("textbox");
  472.  
  473.     // Remove path from style sheet href
  474.     if(position != -1)
  475.     {
  476.         path = styleSheetHref.substring(position + 1);
  477.     }
  478.  
  479.     request.open("GET", styleSheetHref, false);
  480.     request.send("");
  481.  
  482.     stylesText = request.responseText;
  483.  
  484.     tab.setAttribute("label", path);
  485.     textBox.setAttribute("flex", "1");
  486.     textBox.setAttribute("multiline", "true");
  487.     textBox.setAttribute("style", textBoxStyle);
  488.     textBox.setAttribute("value", stylesText);
  489.  
  490.     // If the edit CSS wrap preference is not set to true
  491.     if(!preferencesService.prefHasUserValue("webdeveloper.edit.css.wrap") || !preferencesService.getBoolPref("webdeveloper.edit.css.wrap"))
  492.     {
  493.         textBox.setAttribute("wrap", "off");
  494.     }
  495.  
  496.     tabPanel.appendChild(textBox);
  497.  
  498.     results.push(new Array(tab, tabPanel));
  499.  
  500.     // Loop through the the style sheet rules
  501.     for(var i = 0; i < styleSheet.cssRules.length; i++)
  502.     {
  503.         cssRule = styleSheet.cssRules[i];
  504.  
  505.         // If this is an import rule
  506.         if(cssRule.type == 3)
  507.         {
  508.             webdeveloper_retrieveStyleSheetDetails(cssRule.styleSheet, textBoxStyle, results);
  509.         }
  510.     }
  511.  
  512.     styleSheet.disabled = true;
  513.  
  514.     return results;
  515. }
  516.  
  517. // Saves the CSS
  518. function webdeveloper_saveCSS()
  519. {
  520.     const filePicker   = Components.classes["@mozilla.org/filepicker;1"].createInstance(Components.interfaces.nsIFilePicker);
  521.     const stringBundle = document.getElementById("webdeveloper-string-bundle");
  522.     const styleText    = webdeveloper_getSelectedPanel().firstChild.value;
  523.  
  524.     var result = null;
  525.  
  526.     filePicker.appendFilter(stringBundle.getString("webdeveloper_styleSheetDescription"), "*.css");
  527.     filePicker.init(window, stringBundle.getString("webdeveloper_editCSSSaveStyleSheetTitle"), filePicker.modeSave);
  528.     result = filePicker.show();
  529.  
  530.     // If the user selected a style sheet
  531.     if(result == filePicker.returnOK || result == filePicker.returnReplace)
  532.     {
  533.         const outputStream = Components.classes["@mozilla.org/network/file-output-stream;1"].createInstance(Components.interfaces.nsIFileOutputStream);
  534.  
  535.         // If the file does not exist
  536.         if(!filePicker.file.exists())
  537.         {
  538.             filePicker.file.create(Components.interfaces.nsIFile.NORMAL_FILE_TYPE, 444);
  539.         }
  540.  
  541.         outputStream.init(filePicker.file, 0x04, 0444, null);
  542.  
  543.         outputStream.write(styleText, styleText.length);
  544.         outputStream.close();
  545.     }
  546. }
  547.  
  548. // Toggles sticking the CSS
  549. function webdeveloper_toggleStickCSS()
  550. {
  551.     const preferencesService = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService).getBranch("");
  552.  
  553.     var stick = true;
  554.  
  555.     // If the edit CSS stick preference is set
  556.     if(preferencesService.prefHasUserValue("webdeveloper.edit.css.stick"))
  557.     {
  558.         stick = !preferencesService.getBoolPref("webdeveloper.edit.css.stick");
  559.     }
  560.  
  561.     preferencesService.setBoolPref("webdeveloper.edit.css.stick", stick);
  562.  
  563.     webdeveloper_updateStickCSS();
  564. }
  565.  
  566. // Updates the stick CSS button
  567. function webdeveloper_updateStickCSS()
  568. {
  569.     const preferencesService = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService).getBranch("");
  570.     const stringBundle       = document.getElementById("webdeveloper-string-bundle");
  571.  
  572.     var element = document.getElementById("webdeveloper-stick-css-sidebar");
  573.     var label   = null;
  574.     var stick   = false;
  575.  
  576.     // If the edit CSS stick preference is set
  577.     if(preferencesService.prefHasUserValue("webdeveloper.edit.css.stick"))
  578.     {
  579.         stick = preferencesService.getBoolPref("webdeveloper.edit.css.stick");
  580.     }
  581.  
  582.     // If the element exists
  583.     if(element)
  584.     {
  585.         // If sticking the CSS
  586.         if(stick)
  587.         {
  588.             label = stringBundle.getString("webdeveloper_unstickTooltip");
  589.  
  590.             element.setAttribute("class", "unstick webdeveloper-sidebar-button");
  591.             element.setAttribute("tooltiptext", label);
  592.         }
  593.         else
  594.         {
  595.             label = stringBundle.getString("webdeveloper_stickTooltip");
  596.  
  597.             element.setAttribute("class", "webdeveloper-sidebar-button");
  598.             element.setAttribute("tooltiptext", label);
  599.         }
  600.     }
  601. }